// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'

//导入element库
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css';
import App from './App'
import router from './router'
import TreeTable from 'vue-table-with-tree-grid'
import VueQuillEditor from 'vue-quill-editor'
// 头部进度条
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

//导入全局样式表
import './assets/css/global.css'
//富文本样式
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'

//导入图标样式表
import './assets/fonts/iconfont.css'
import axios from 'axios'
axios.defaults.baseURL = 'http://127.0.0.1:8888/api/private/v1/'

// 配置axios请求拦截器 添加token 保证拥有获取数据的权限
axios.interceptors.request.use(cfg => {

  // 显示头部进度条
  NProgress.start()

  // 给请求头添加token
  cfg.headers.Authorization = window.sessionStorage.getItem('token');
  // 最后必须return cfg
  return cfg;
})

// 得到Ajax响应后 隐藏头部进度条
axios.interceptors.response.use(cfg => {
  // 隐藏头部进度条
  NProgress.done()
  return cfg
})

// 挂载全局属性到原型
Vue.prototype.$http = axios
Vue.prototype.$message = ElementUI.Message
Vue.prototype.$confirm = ElementUI.confirm

Vue.config.productionTip = false
Vue.use(ElementUI);
Vue.component(TreeTable.name, TreeTable)
Vue.use(VueQuillEditor)

//全局时间过滤器 (过滤器名字,处理函数)
Vue.filter('dateFormat', function (originVal) {
  const dt = new Date(originVal)
  const y = dt.getFullYear()
  const m = (dt.getMonth() + 1 + '').padStart(2, '0') //1.月份从0开始 2.转换成字符串 3.不够两位时用0补
  const d = (dt.getDate() + '').padStart(2, '0')

  const hh = (dt.getHours() + '').padStart(2, '0')
  const mm = (dt.getMinutes() + '').padStart(2, '0')
  const ss = (dt.getSeconds() + '').padStart(2, '0')

  return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
